package com.hyj.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hyj.entity.Memberships;
import com.hyj.entity.Students;
import com.hyj.service.MemService;
import com.hyj.service.StuService;



@Controller
public class StuController {
	@Autowired
	private MemService memService;
	@Autowired
	private StuService stuService;
	
	
		/**
		 * 全查学生
		 * @param Students
		 * @return
		 */
		@ResponseBody
		@RequestMapping("/getStus")
		public Object getStu(Students stu) {
			List<Students> list = stuService.getStu(stu);
			stu.setPage(null);
			stu.setLimit(null);

			System.out.println("查得到学生全部数据" + list);
			Map<String, Object> map = new HashMap<String, Object>();
			List<Students> list2 = stuService.getStu(stu);
			map.put("code", 0);
			map.put("msg", "学生列表");
			map.put("count", list2.size()); 
			map.put("data", list);
			return map;
		}
		
		
		@RequestMapping("/getStuMem")
		public Object getStuMem(ModelMap map) {
			List<Memberships> list = memService.getMem(null);
			map.put("stuList", list); 

			return "stuList";
		}
		
		/**
		 * 添加学生方法
		 * @param s
		 * @return
		 */
		@ResponseBody
		@RequestMapping("/addStu")
		public Object addStu(Students stu) {
			int st = stuService.addStu(stu);
			System.out.println("拿到的添加的学生数据" + stu);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("code", 0);
			map.put("msg", "学生添加");
			map.put("count", 100); 
			map.put("data", st); 
			return map;
		}
		/**
		 * 删除学生方法
		 * @param id
		 * @return
		 */
		@ResponseBody
		@RequestMapping("/delStu")
		public Object delStu (Integer StuId) {
			System.out.println("拿到删除学生ID:"+StuId);
			int sno=stuService.delStu(StuId);
			System.out.println("拿到删除后学生的信息："+sno);
			return sno;
		}
		/**
		 * 修改学生方法
		 * @param s
		 * @return
		 */
		@ResponseBody
		@RequestMapping("/updateStu")
		public Object updateStu(Students StuId) {
			int stu = stuService.updateStu(StuId);
			System.out.println("拿到修改学生信息的数据："+StuId);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("code", 0);
			map.put("msg", "学生修改");
			map.put("count", 100); 
			map.put("data", stu); 
			return map;
		}
		
	
	
}
